#!/bin/sh
#nginx自动化安装脚本

echo "----- nginx自动化安装脚本开始执行 -----"
#安装pcre-devel
cd ../rpm/nginx
rpm  -ivh  *.rpm --nodeps --force

#安装nginx
echo "----- 安装nginx -----"
tar -zxvf nginx-1.12.2.tar.gz -C ../../temp
cd ../../temp/nginx-1.12.2
./configure --add-module=../fastdfs-nginx-module/src
make
make install
# 修改nginx配置
echo "----- 修改nginx配置 -----"
cp -f ./conf/nginx.conf /usr/local/nginx/conf/
cp -f ../../conf/nginx.service /lib/systemd/system/
sed -i '47a location ~/group([0-9])/ { \n ngx_fastdfs_module; \n }' /usr/local/nginx/conf/nginx.conf
# 设置nginx开机自启
echo "----- 设置nginx开机自启 -----"
systemctl enable nginx
# 启动nginx
echo "----- 启动nginx -----"
systemctl start nginx
#开放80端口访问权限
echo "----- 开放80端口访问权限 -----"
systemctl start firewalld
if [ $? -eq 0 ];then
   echo "----- 成功开启防火墙 -----"
else
   echo "----- 防火墙开启失败，脚本退出 -----"
   exit 1
fi
firewall-cmd --zone=public --add-port=80/tcp --permanent
if [ $? -eq 0 ];then
   firewall-cmd --reload
   echo "----- 80端口开启成功 -----"
else
   echo "----- 80端口开启失败，脚本退出 -----"
   exit 1
fi
echo "----- nginx自动化安装脚本执行完毕 -----"

